#!/bin/bash

ns=$1
svc=$2

if [ "$ns"x == ""x ] ; then
	exist=args1-empty
	echo $exist
	exit 1
fi

if [ "$svc"x == ""x ] ; then
	exist=args2-empty
	echo $exist
	exit 1
fi

kubectl --kubeconfig=/etc/kubernetes/{{ cluster_name }}/admin.conf get ep -n $ns $svc >/dev/null
if [ $? -eq 1 ] ; then
	exist=service-no-exist
	echo $exist
	exit 1
fi

for ((i=0;i<60;i++)); do
	output=`kubectl --kubeconfig=/etc/kubernetes/{{ cluster_name }}/admin.conf get ep -n $ns $svc |grep -v NAME | awk '{print $2}'`
	if [ "$output"x == "<none>"x ] ; then
		exist=no
		sleep 1
		continue
	else
		exist=yes
		break
	fi
done
echo $exist
